package com.lyf.scm.plan.domain.service.impl;

import cn.hutool.core.date.DateUtil;
import com.lyf.scm.common.constants.BigDataEsConstants;
import com.lyf.scm.common.constants.CommonConstants;
import com.lyf.scm.common.enums.OpContentEnum;
import com.lyf.scm.common.enums.OperationDataEnum;
import com.lyf.scm.common.enums.ResponseMsg;
import com.lyf.scm.plan.api.dto.StoreInfoDTO;
import com.lyf.scm.plan.domain.convertor.BigDataBaseConvertor;
import com.lyf.scm.plan.domain.remote.bigdata.dto.BigDataGeneralInfoDTO;
import com.lyf.scm.plan.domain.remote.bigdata.dto.BigDataGeneralQueryBaseDTO;
import com.lyf.scm.plan.domain.remote.bigdata.facade.CprfCoreFacade;
import com.lyf.scm.plan.domain.remote.item.dto.CategorySimpleDTO;
import com.lyf.scm.plan.domain.remote.item.dto.SkuInfoDTO;
import com.lyf.scm.plan.domain.remote.item.facade.ItemCoreFacade;
import com.lyf.scm.plan.domain.repository.OperationLogRecordRepository;
import com.lyf.scm.plan.domain.service.RequirementsPlanningService;
import com.lyf.scm.plan.domain.util.OperationLogRecordUtil;
import com.lyf.scm.plan.domain.util.RequirementsPlanningCacheUtil;
import com.lyf.scm.plan.insfrastructure.db.dataobject.OperationLogRecordDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.*;
import com.rome.arch.util.IdWorker;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static com.lyf.scm.plan.domain.util.RequirementsPlanningCacheUtil.*;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;

/**
 * 需求计划
 *
 * @author wangchlei
 * @date 2020/10/12
 */
@Slf4j
@Service
public class RequirementsPlanningServiceImpl implements RequirementsPlanningService {
    //    @Resource
//    private RedisCacheServiceImpl redisCacheServiceImpl;
//    @Resource
//    private OperationLogRecordRepository operationLogRecordRepository;
    @Resource
    private ElasticsearchTemplate elasticsearchTemplate;
//    @Resource
//    private ItemCoreFacade itemCoreFacade;
//    @Resource
//    private BigDataBaseConvertor bigDataBaseConvertor;
//    /**
//     * 远程调用
//     */
//    @Resource
//    private CprfCoreFacade cprfCoreFacade;
//    /**
//     * 标识
//     */
//    private String opSign;

    @Override
    public void createIndex() {
        //创建索引
        elasticsearchTemplate.createIndex(RequirementsPlanningEntity.class);
        elasticsearchTemplate.putMapping(RequirementsPlanningEntity.class);
    }

//    /**
//     * 拉取大数据数据（调用日补货接口，所有门店）
//     *
//     * @param
//     * @return void
//     **/
//    @Async
//    @Override
//    public void handleApiDispatcher() {
//        long startTime = System.currentTimeMillis();
//        Date date = new Date();
//        if (!validWeekJob(date)) {
//            return;
//        }
//        Map<String, StoreInfoDTO> storesInfo = redisCacheServiceImpl.getAllStores();
//        log.info("\n【大数据Job】：已获取所有门店,门店数量 {}", storesInfo.size());
//        //初始化必要数据的缓存
//        this.initCacheData(date);
//        log.info("\n【大数据Job】：开始处理所有门店");
//        storesInfo.keySet().forEach(item -> this.handleStore(storesInfo.get(item)));
//        long endTime = System.currentTimeMillis();
//        this.writeOperateLog(endTime - startTime);
//    }
//
//    private void handleStore(StoreInfoDTO storeInfo) {
//        long globalStartTime = System.currentTimeMillis();
//        List<IndexQuery> queryList;
//        //大数据信息
//        long handleStartTime = System.currentTimeMillis();
//        List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs = null;
//        try {
//            //获取查询条件
//            BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO = this.getGeneralQueryBaseDTO(storeInfo.getCode(), RequirementsPlanningCacheUtil.nowDate);
//            //根据时间段，门店等信息  递归分页获取所有大数据信息
//            bigDataGeneralInfoDTOs = this.getBigDataGeneralInfo(bigDataGeneralQueryBaseDTO);
//            //合理默认两个表的状态是统一的，且其数据量数据结构是一致的（数据数量，sku,门店等是统一的）
//            if (!CollectionUtils.isEmpty(bigDataGeneralInfoDTOs)) {
//                queryList = this.getResult(storeInfo, bigDataGeneralInfoDTOs);
//            } else {
//                log.warn("\n【大数据Job】：门店数据无数据：code {}  name {}", storeInfo.getCode(), storeInfo.getName());
//                return;
//            }
//        } catch (feign.RetryableException retryableException) {
//            long handleEndTime = System.currentTimeMillis();
//            retryableException.printStackTrace();
//            log.error("\n【大数据Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：" + retryableException.getMessage());
//            this.writeErrorLog(storeInfo.getCode(), retryableException.getMessage(), (handleEndTime - handleStartTime), bigDataGeneralInfoDTOs.size());
//            return;
//        } catch (Exception e) {
//            long handleEndTime = System.currentTimeMillis();
//            e.printStackTrace();
//            log.error("\n【大数据Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：" + ResponseMsg.FAIL_5004.getMsg());
//            this.writeErrorLog(storeInfo.getCode(), ResponseMsg.FAIL_5004.getMsg(), (handleEndTime - handleStartTime), bigDataGeneralInfoDTOs.size());
//            return;
//        }
//        long sqlStartTime = System.currentTimeMillis();
//        try {
//            this.handleBigData(queryList);
//        } catch (Exception e) {
//            long sqlEndTime = System.currentTimeMillis();
//            e.printStackTrace();
//            log.error("\n【大数据Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：" + ResponseMsg.FAIL_5005.getMsg());
//            this.writeErrorLog(storeInfo.getCode(), ResponseMsg.FAIL_5005.getMsg(), (sqlEndTime - sqlStartTime), queryList.size());
//            return;
//        }
//        long globalEndTime = System.currentTimeMillis();
//        log.info("\n【大数据Job】：门店数据处理成功：code {}  name {}  耗时 {}", storeInfo.getCode(), storeInfo.getName(), (globalEndTime - globalStartTime) + "ms");
//    }
//
//    /**
//     * 将结果写入es
//     *
//     * @param queryList
//     * @return void
//     **/
//    private void handleBigData(List<IndexQuery> queryList) {
//        long startTime = System.currentTimeMillis();
//        if (!CollectionUtils.isEmpty(queryList)) {
//            List<List<IndexQuery>> lists = splitTo(queryList, 50000);
//            for (List<IndexQuery> list : lists) {
//                elasticsearchTemplate.bulkIndex(list);
//            }
//        }
//        long endTime = System.currentTimeMillis();
//        log.info("\n【大数据Job】：写入耗时 {}", (endTime - startTime) + "ms");
//    }
//
//    /**
//     * 写错误日志到mysql
//     *
//     * @param storeCode
//     * @param msg
//     * @param time
//     * @param size
//     * @return void
//     **/
//    private void writeErrorLog(String storeCode, String msg, long time, int size) {
//        List<OperationLogRecordDO> operationLogRecordDOs = new ArrayList<>(1);
//        operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataErrorLog(storeCode, OperationDataEnum.REQUIREMENTS_PLANNING.getTableType(), msg, size, time + "ms", OpContentEnum.BIG_DATA_ERROR_REQUIRE_LOG.getIndex(), OpContentEnum.BIG_DATA_ERROR_REQUIRE_LOG.getDesc()));
//        operationLogRecordRepository.batchAddBigDataErrorLog(operationLogRecordDOs);
//    }
//
//    private List<IndexQuery> getResult(StoreInfoDTO storeInfo, List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs) {
//        List<RequirementsPlanningEntity> upRequirementsPlanningEntitys = this.getHistoryOfRequirement(storeInfo.getCode());
//        if (CollectionUtils.isEmpty(upRequirementsPlanningEntitys)) {
//            upRequirementsPlanningEntitys = new ArrayList<>(1);
//        }
//        return this.initalUpData(upRequirementsPlanningEntitys, storeInfo, bigDataGeneralInfoDTOs);
//    }
//
//    private List<IndexQuery> initalUpData(List<RequirementsPlanningEntity> upRequirementsPlanningEntitys, StoreInfoDTO storeInfo, List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs) {
//        //查询sku信息
//        List<SkuInfoDTO> skuInfoDTOS = itemCoreFacade.skuListBySkuCodes(bigDataGeneralInfoDTOs.stream().map(BigDataGeneralInfoDTO::getSkuKey).distinct().collect(Collectors.toList()));
//        Map<String, SkuInfoDTO> skuCodeName = this.getSkuInfo(skuInfoDTOS);
//        Map<Integer, List<CategorySimpleDTO>> categoryInfo = this.getCategoryInfo(skuInfoDTOS);
//        //遍历
//        int countDirect;
//        String skuKey;
//        RequirementsPlanningEntity requirementsPlanningEntity;
//        List<IndexQuery> queryList = new ArrayList<>();
//        for (BigDataGeneralInfoDTO bigDataGeneralInfoDTO : bigDataGeneralInfoDTOs) {
//            skuKey = bigDataGeneralInfoDTO.getSkuKey();
//            //直营预测————门店
//            countDirect = 0;
//            //如果含有更新数据————加入门店第十四天新增数据   执行所有新增数据,否则新增所有天数据
//            requirementsPlanningEntity = this.createGeneralDayInDO(skuKey, storeInfo, skuCodeName, categoryInfo);
//            //遍历十三周数据
//            for (RequirementsPlanningEntity item : upRequirementsPlanningEntitys) {
//                if (skuKey.equals(item.getSkuCode())) {
//                    this.setGeneralInfo(item, skuKey, storeInfo, skuCodeName, categoryInfo);
//                    this.setRequirementGeneralValue(item, bigDataGeneralInfoDTO);
//                    //设置es更新对象
//                    queryList.add(new IndexQueryBuilder().withObject(item).withId(item.getId()).build());
//                    countDirect++;
//                }
//            }
//            if (countDirect != 0) {
//                queryList.add(this.getNewRequirement(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesWeekf13()));
//            } else {
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf1(), startDateStr1, endDateStr1);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf2(), startDateStr2, endDateStr2);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf3(), startDateStr3, endDateStr3);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf4(), startDateStr4, endDateStr4);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf5(), startDateStr5, endDateStr5);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf6(), startDateStr6, endDateStr6);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf7(), startDateStr7, endDateStr7);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf8(), startDateStr8, endDateStr8);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf9(), startDateStr9, endDateStr9);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf10(), startDateStr10, endDateStr10);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf11(), startDateStr11, endDateStr11);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf12(), startDateStr12, endDateStr12);
//                this.getWeekDO(requirementsPlanningEntity, queryList, bigDataGeneralInfoDTO.getSalesWeekf13(), startDateStr13, endDateStr13);
//            }
//        }
//        return queryList;
//    }
//
//    private void getWeekDO(RequirementsPlanningEntity requirementsPlanningEntity, List<IndexQuery> queryList, BigDecimal sales, String startDate, String endDate) {
//        RequirementsPlanningEntity requirementsPlanning = bigDataBaseConvertor.baseEnToRequirementEn(requirementsPlanningEntity);
//        requirementsPlanning.setForecastPlanVolume(sales);
//        requirementsPlanning.setPlanStartDate(startDate);
//        requirementsPlanning.setPlanEndDate(endDate);
//        queryList.add(new IndexQueryBuilder().withObject(requirementsPlanning).build());
//    }
//
//    private IndexQuery getNewRequirement(RequirementsPlanningEntity requirementsPlanningEntity, BigDecimal sales) {
//        RequirementsPlanningEntity requirementsPlanning = bigDataBaseConvertor.baseEnToRequirementEn(requirementsPlanningEntity);
//        requirementsPlanning.setForecastPlanVolume(sales);
//        requirementsPlanning.setPlanStartDate(startDateStr13);
//        requirementsPlanning.setPlanEndDate(endDateStr13);
//        return new IndexQueryBuilder().withObject(requirementsPlanning).build();
//    }
//
//    private void setRequirementGeneralValue(RequirementsPlanningEntity requirementsPlanningEntity, BigDataGeneralInfoDTO bigDataGeneralInfoDTO) {
//        //获取对应日期的预测值
//        String startDateStr = requirementsPlanningEntity.getPlanStartDate();
//        if (startDateStr1.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesWeekf1());
//            return;
//        }
//        if (startDateStr2.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf2());
//            return;
//        }
//        if (startDateStr3.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf3());
//            return;
//        }
//        if (startDateStr4.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf4());
//            return;
//        }
//        if (startDateStr5.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf5());
//            return;
//        }
//        if (startDateStr6.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf6());
//            return;
//        }
//        if (startDateStr7.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf7());
//            return;
//        }
//        if (startDateStr8.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf8());
//            return;
//        }
//        if (startDateStr9.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf9());
//            return;
//        }
//        if (startDateStr10.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf10());
//            return;
//        }
//        if (startDateStr11.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf11());
//            return;
//        }
//        if (startDateStr12.equals(startDateStr)) {
//            this.setRequirementValue(requirementsPlanningEntity, bigDataGeneralInfoDTO.getSalesDayf12());
//        }
//    }
//
//    private void setRequirementValue(RequirementsPlanningEntity requirementsPlanningEntity, BigDecimal sales) {
//        requirementsPlanningEntity.setForecastPlanVolume(sales);
//    }
//
//    private void setGeneralInfo(RequirementsPlanningEntity requirementsPlanningEntity, String skuKey, StoreInfoDTO storeInfo, Map<String, SkuInfoDTO> skuCodeName, Map<Integer, List<CategorySimpleDTO>> categoryInfo) {
//        requirementsPlanningEntity.setOpSign(opSign);
//        //设置省市区 门店
//        this.setGeneralAreaValue(requirementsPlanningEntity, storeInfo);
//        //设置大中小品类
//        if (skuCodeName.get(skuKey) != null) {
//            SkuInfoDTO skuInfoDTO = skuCodeName.get(skuKey);
//            List<CategorySimpleDTO> categorySimpleDTOS = categoryInfo.get(skuInfoDTO.getCategoryId());
//            if (!CollectionUtils.isEmpty(categorySimpleDTOS)) {
//                RequirementsPlanningEntity finalRequirementsPlanningEntity = requirementsPlanningEntity;
//                categorySimpleDTOS.forEach(subItem -> this.setGeneralCategoryValue(subItem, finalRequirementsPlanningEntity));
//            }
//        }
//    }
//
//    private RequirementsPlanningEntity createGeneralDayInDO(String skuKey, StoreInfoDTO storeInfo, Map<String, SkuInfoDTO> skuCodeName, Map<Integer, List<CategorySimpleDTO>> categoryInfo) {
//        RequirementsPlanningEntity requirementsPlanningEntity = new RequirementsPlanningEntity();
//        requirementsPlanningEntity.setOpSign(opSign);
//        //设置省市区 门店
//        this.setGeneralAreaValue(requirementsPlanningEntity, storeInfo);
//        requirementsPlanningEntity.setStoreCode(storeInfo.getCode());
//        //设置大中小品类
//        requirementsPlanningEntity.setSkuCode(skuKey);
//        if (skuCodeName.get(skuKey) != null) {
//            SkuInfoDTO skuInfoDTO = skuCodeName.get(skuKey);
//            List<CategorySimpleDTO> categorySimpleDTOS = categoryInfo.get(skuInfoDTO.getCategoryId());
//            if (!CollectionUtils.isEmpty(categorySimpleDTOS)) {
//                RequirementsPlanningEntity finalRequirementsPlanningEntity = requirementsPlanningEntity;
//                categorySimpleDTOS.forEach(subItem -> this.setGeneralCategoryValue(subItem, finalRequirementsPlanningEntity));
//            }
//        }
//        return requirementsPlanningEntity;
//    }
//
//    /**
//     * 设置通用属性 设置品类
//     *
//     * @param subItem
//     * @return void
//     **/
//    private void setGeneralCategoryValue(CategorySimpleDTO subItem, RequirementsPlanningEntity requirementsPlanningEntityy) {
//        Integer level = subItem.getCategoryLevel();
//        switch (level) {
//            case 2:
//                requirementsPlanningEntityy.setPriCategoryCode(String.valueOf(subItem.getCategoryCode()));
//                break;
//            case 3:
//                requirementsPlanningEntityy.setSecCategoryCode(String.valueOf(subItem.getCategoryCode()));
//                break;
//            case 4:
//                requirementsPlanningEntityy.setTerCategoryCode(String.valueOf(subItem.getCategoryCode()));
//                break;
//            default:
//        }
//    }
//
//    /**
//     * 设置通用属性 设置省市区 门店
//     *
//     * @param storeInfo
//     * @return void
//     **/
//    private void setGeneralAreaValue(RequirementsPlanningEntity requirementsPlanningEntity, StoreInfoDTO storeInfo) {
//        requirementsPlanningEntity.setProvinceCode(storeInfo.getProvinceCode());
//        requirementsPlanningEntity.setCityCode(storeInfo.getCityCode());
//        requirementsPlanningEntity.setCountyCode(storeInfo.getAreaCode());
//    }
//
//    /**
//     * 根据skuInfo获取sku品类信息
//     *
//     * @param skuInfoDTOS
//     * @return void
//     **/
//    private Map<Integer, List<CategorySimpleDTO>> getCategoryInfo(List<SkuInfoDTO> skuInfoDTOS) {
//        Map<Integer, List<CategorySimpleDTO>> categoryInfo = new HashMap<>();
//        if (!CollectionUtils.isEmpty(skuInfoDTOS)) {
//            List<CategorySimpleDTO> categorySimpleDTOS = itemCoreFacade.getAllCategoryByCategoryId(skuInfoDTOS.stream().map(SkuInfoDTO::getCategoryId).distinct().collect(Collectors.toList()));
//            categoryInfo = categorySimpleDTOS.stream().collect(Collectors.toMap(CategorySimpleDTO::getId, CategorySimpleDTO::getParentCategoryDTOList));
//        }
//        return categoryInfo;
//    }
//
//    /**
//     * 根据skuInfo获取sku-map信息
//     *
//     * @param skuInfoDTOS
//     * @return void
//     **/
//    private Map<String, SkuInfoDTO> getSkuInfo(List<SkuInfoDTO> skuInfoDTOS) {
//        //根据skuCodes查询skuInfo
//        Map<String, SkuInfoDTO> skuCodeName = new HashMap<>();
//        if (!CollectionUtils.isEmpty(skuInfoDTOS)) {
//            skuCodeName = skuInfoDTOS.stream().collect(Collectors.toMap(SkuInfoDTO::getSkuCode, item -> item));
//        }
//        return skuCodeName;
//    }
//
//    private List<RequirementsPlanningEntity> getHistoryOfRequirement(String storeCode) {
//        // 获取所有周查询条件条件查询
//        List<SearchQuery> groupQuerys = this.getWeekSearchQuerys(BigDataEsConstants.INDEX_NAME_PLAN_REQUIREMENT, storeCode);
//        //根据所有查询条件获取数据
//        return this.getEsQueryResult(groupQuerys, RequirementsPlanningEntity.class);
//    }
//
//    private <T> List<T> getEsQueryResult(List<SearchQuery> groupQuerys, Class<T> entityClass) {
//        List<T> entitys = new ArrayList<>();
//        for (SearchQuery groupQuery : groupQuerys) {
//            entitys.addAll(elasticsearchTemplate.queryForList(groupQuery, entityClass));
//        }
//        return entitys;
//    }
//
//    private List<SearchQuery> getWeekSearchQuerys(String indexName, String storeCode) {
//        List<SearchQuery> searchQuerys = new ArrayList<>();
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr1));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr2));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr3));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr4));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr5));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr6));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr7));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr8));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr9));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr10));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr11));
//        searchQuerys.add(this.getWeekSearchQuery(indexName, storeCode, startDateStr12));
//        return searchQuerys;
//    }
//
//    private SearchQuery getWeekSearchQuery(String indexName, String storeCode, String startDateStr) {
//        return new NativeSearchQueryBuilder()
//                .withQuery(
//                        QueryBuilders.boolQuery()
//                                .filter(termQuery("planStartDate", startDateStr))
//                                .must(matchQuery("storeCode", storeCode))
//                ).withIndices(indexName).withPageable(PageRequest.of(0, 10000)).build();
//    }
//
//    /**
//     * 循环获取日补货接口数据
//     *
//     * @param bigDataGeneralQueryBaseDTO
//     * @return void
//     **/
//    private List<BigDataGeneralInfoDTO> getBigDataGeneralInfo(BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO) {
//        List<BigDataGeneralInfoDTO> itemDTOS = cprfCoreFacade.getDayPredictReplenishment(bigDataGeneralQueryBaseDTO);
//        List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs = new ArrayList<>(itemDTOS);
//        while (itemDTOS.size() == CommonConstants.BIG_DATA_PAGE_SIZE) {
//            bigDataGeneralQueryBaseDTO.setPageNo(bigDataGeneralQueryBaseDTO.getPageNo() + 1);
//            itemDTOS = cprfCoreFacade.getDayPredictReplenishment(bigDataGeneralQueryBaseDTO);
//            bigDataGeneralInfoDTOs.addAll(itemDTOS);
//        }
//        return bigDataGeneralInfoDTOs;
//    }
//
//    /**
//     * 大数据查询实体
//     *
//     * @param storeCode
//     * @param nowDateStr
//     * @return {@link BigDataGeneralQueryBaseDTO}
//     **/
//    private BigDataGeneralQueryBaseDTO getGeneralQueryBaseDTO(String storeCode, String nowDateStr) {
//        BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO = new BigDataGeneralQueryBaseDTO();
//        bigDataGeneralQueryBaseDTO.setStartDate(nowDateStr);
//        bigDataGeneralQueryBaseDTO.setEndDate(nowDateStr);
//        bigDataGeneralQueryBaseDTO.setStore(storeCode);
//        bigDataGeneralQueryBaseDTO.setPageNo(1);
//        bigDataGeneralQueryBaseDTO.setPageSize(CommonConstants.BIG_DATA_PAGE_SIZE);
//        return bigDataGeneralQueryBaseDTO;
//    }
//
//    private void initCacheData(Date date) {
//        //注入周和日的处理缓存信息
//        RequirementsPlanningCacheUtil.injectWeekCache(date);
//        //数据标识
//        IdWorker idWorker = new IdWorker();
//        opSign = "" + idWorker.getId();
//    }
//
//    /**
//     * 判断是否需要触发周数据任务（默认为每周一才能触发）
//     *
//     * @param
//     * @return {@link boolean}
//     **/
//    private boolean validWeekJob(Date date) {
//        return DateUtil.dayOfWeek(date) == 2;
//    }
//
//    private void writeOperateLog(long time) {
//        //插入该批次数据日志
//        List<OperationLogRecordDO> operationLogRecordDOs = new ArrayList<>(1);
//        operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataOperationLog(opSign, OperationDataEnum.REQUIREMENTS_PLANNING.getTableType(), time + "ms", OpContentEnum.BIG_DATA_OPERATION_REQUIRE_LOG.getIndex(), OpContentEnum.BIG_DATA_OPERATION_REQUIRE_LOG.getDesc()));
//        operationLogRecordRepository.batchAddOperationLogRecord(operationLogRecordDOs);
//    }
}
